from django.db.models.signals import post_save
from django.dispatch import receiver
from .models import Mission, MissionDetail, MissionBasicInfo, MissionContent, MissionStatus

@receiver(post_save, sender=Mission)
def create_mission_related_data(sender, instance, created, **kwargs):
    """
    当 Mission 被创建时，自动创建关联的 MissionDetail、MissionBasicInfo、MissionContent 和 MissionStatus 实例。
    """
    if created:
        # 创建 MissionDetail 实例
        MissionDetail.objects.create(mission=instance)
        
        # 创建 MissionBasicInfo 实例
        MissionBasicInfo.objects.create(mission=instance)
        
        # 创建 MissionContent 实例
        MissionContent.objects.create(mission=instance,content=[])
        
        # 创建 MissionStatus 实例
        MissionStatus.objects.create(mission=instance)